#ifndef __NCE_SOCKET_H__
#define __NCE_SOCKET_H__

#include <iostream>

#include "nce_buffer.h"
#include "nce_servant.h"

using namespace std;

namespace nce
{

class Socket
{
public:
	int send(const char *buffer, size_t length);
	int send(OutputBuffer &ob);
	
    int recv(char *buffer, size_t &length);
	int recv(InputBuffer &ib);
	
protected:
	int open_clientfd(const char *hostname, int port);
	int open_listenfd(int port);
	
	int _socket;
};

class ClientSocket : public Socket
{
public:
    ClientSocket(string hostName, int port)
    {
        _hostName = hostName;
        _port = port;
        _socket = open_clientfd(_hostName.c_str(), _port);
    }

    ~ClientSocket() { close(_socket); }
	
private:
    string _hostName;
    int _port;
};

class ServerSocket : public Socket
{
public:
    ServerSocket(int port) : _port(port) {}
    int start(class Servant *servant);
	
private:
    int _port;
};

class EpollServerSocket : public ServerSocket
{

};

}

#endif
